<script>
	export default {
		data() {
			return {
				timer: null, // 定时器
				id: '',
				total: 0,
				userinfoAll: ''
			}
		},


		onLaunch: function() {
			console.warn('当前组件仅支持 uni_modules 目录结构 ，请升级 HBuilderX 到 3.1.0 版本以上！')
			console.log('App Launch')
		},
		onShow: function() {
			this.userinfoAll = uni.getStorageSync('userinfoAll');
			console.log(this.userinfoAll)

			console.log('App Show')
			let that = this
			if (this.userinfoAll.is_taker == 1) {
				this.timer = setInterval(function() {
					that.getorderlistApi()
				}, 3000)
			}
		},
		watch: {
			total(newVal, oldVal) {
				this.playNotificationSound()
			}
		},
		onLoad() {

		},
		onHide: function() {
			console.log('App Hide')
		},
		methods: {
			// 显示订单列表
			getorderlistApi() {
				this.get('/api/newadd/getorderlist', {
					status: 2,
					taker_id: ''
				}).then((res) => {
					this.total = res.total
					console.log(this.total, "================totaltotaltotaltotaltotal")
				})
			},
			playNotificationSound() {
				const innerAudioContext = uni.createInnerAudioContext();
				innerAudioContext.autoplay = true;
				innerAudioContext.src = 'static/notification.mp3'; //铃声文件的路径
				innerAudioContext.onPlay(() => {
					console.log('开始播放');
				});
				innerAudioContext.onError((res) => {
					console.log(res.errMsg);
					console.log(res.errCode);
				});

				// #ifdef APP-PLUS
				if (uni.getSystemInfoSync().platform == "ios") {
					plus.device.vibrate();
					plus.device.beep();

				} else if (uni.getSystemInfoSync().platform == "android") {
					// 震动
					plus.device.vibrate(500);
					//声音
					let main = plus.android.runtimeMainActivity();
					let RingtoneManager = plus.android.importClass("android.media.RingtoneManager");
					let uri = RingtoneManager.getActualDefaultRingtoneUri(main, RingtoneManager.TYPE_NOTIFICATION);
					let MediaPlayer = plus.android.importClass("android.media.MediaPlayer");
					let player = MediaPlayer.create(main, uri);
					player.setLooping(false);
					player.prepare();
					player.start();
				}
				// #endif
				// #ifdef H5 || MP-WEIXIN
				uni.vibrateLong({
					success: function() {
						console.log('success');
					}
				});
				// #endif
			},
		}
	}
</script>

<style lang="scss">
	/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
	@import "@/uni_modules/uview-ui/index.scss";
	/*每个页面公共css */
	@import '@/uni_modules/uni-scss/index.scss';
	/* #ifndef APP-NVUE */
	@import '@/static/customicons.css';

	// 设置整个项目的背景色
	page {
		background-color: #f5f5f5;
	}

	/* #endif */
	.example-info {
		font-size: 14px;
		color: #333;
		padding: 10px;
	}
</style>